<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <% String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";%>
    <link rel="stylesheet" href="<%=basePath%>/css/login.css"/>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-3.6.0.js"></script>
    <style type="text/css">

        button { /* 按钮美化 */
            width: 120px; /* 宽度 */
            height: 40px; /* 高度 */
            border-width: 0px; /* 边框宽度 */
            border-radius: 3px; /* 边框半径 */
            background: #1E90FF; /* 背景颜色 */
            cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
            outline: none; /* 不显示轮廓线 */
            font-family: Microsoft YaHei; /* 设置字体 */
            color: white; /* 字体颜色 */
            font-size: 17px; /* 字体大小 */
            margin-top: 15px;
        }

        button:hover { /* 鼠标移入按钮范围时改变颜色 */
            background: #5599FF;
        }
    </style>
</head>
<body>
<stection>
    <!-- 背景色 -->
    <div class="color"></div>
    <div class="color"></div>
    <div class="color"></div>
    <div class='box'>
        <!-- 背景圆 -->
        <div class="circle" style="--x:0"></div>
        <div class="circle" style="--x:1"></div>
        <div class="circle" style="--x:2"></div>
        <div class="circle" style="--x:3"></div>
        <div class="circle" style="--x:4"></div>
        <div class='container'>
            <div class="from">
                <h1>欢迎来到登录页面</h1>
                <form class="form-horizontal">
                    <div class="inputbox">
                        <label for="inputUsername" class="col-sm-2 control-label" for="inputUsername">用户名:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="inputUsername" name="username">
                        </div>
                    </div>
                    <p></p>
                    <div class="inputbox">
                        <label for="inputPassword" class="col-sm-2 control-label" for="inputPassword">密码:</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="inputPassword" name="password">
                        </div>
                    </div>
                    <p></p>
                    <div>
                        <div class="loginbutton">
                            <div class="twobutton">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="button" class="btn btn-default" onclick="login2()">系统管理员登录</button>
                                </div>
                            </div>
                        </div>
                        <p></p>
                        <div class="loginbutton">
                            <div class="onebutton">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="button" class="btn btn-default" onclick="login()">宿舍管理员登录</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <p class="forget">没有账号？<a href="admin/register">点击注册</a></p>
                </form>
            </div>
        </div>
    </div>
</stection>
<script>
    function login2() {
        var username = $("#inputUsername").val();
        var password = $("#inputPassword").val();
        if (username == "") {
            alert("请输入用户名");
            return false;
        } else if (password == "") {
            alert("请输入密码");
            return false;
        }
        $.ajax({
            type: "post",
            url: "admin/login",
            data: {username: username, password: password},
            dataType: "json",
            success: function (data) {
                if (data.code == "1") {
                    window.location.href = "admin/success2";
                } else  {
                    alert("用户名或密码错误");
                }
            },
            error: function (err) {
                alert(JSON.stringify(err))
            }
        });
    }

    function login() {
        var username = $("#inputUsername").val();
        var password = $("#inputPassword").val();
        if (username == "") {
            alert("请输入用户名");
            return false;
        } else if (password == "") {
            alert("请输入密码");
            return false;
        }
        $.ajax({
            type: "post",
            url: "manager/login",
            data: {username: username, password: password},
            dataType: "json",
            success: function (data) {
                if (data.code == "1") {
                    window.location.href = "admin/success";
                } else {
                    alert("用户名或密码错误");
                }
            }
            ,
            error: function (err) {
                alert(JSON.stringify(err))
            }
        });
    }
</script>
</body>
</html>
